package netctoss.demo.mapper;

import netctoss.demo.entrty.Service;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

public class ServiceSqlProvider {

    public String selectPage(Service condition){
        return new SQL(){{
            SELECT("s.*,c.cost_name costName,a.account_idcard_no accountIdcardNo,a.account_real_name accountRealName,c.cost_descr costDescr ");
            FROM("service s ");
            LEFT_OUTER_JOIN("cost c on s.cost_id=c.cost_id left join account a on s.account_id=a.account_id ");
            if (!StringUtils.isEmpty(condition.getOsUsername())) {
                WHERE("s.os_username like concat('%',#{osUsername},'%') ");
            }
            if (!StringUtils.isEmpty(condition.getUnixHost())) {
                WHERE("s.unix_host like concat('%',#{unixHost},'%') ");
            }
            if (!StringUtils.isEmpty(condition.getAccountIdcardNo())) {
                WHERE("a.account_idcard_no like concat('%',#{accountIdcardNo},'%') ");
            }
            if (!StringUtils.isEmpty(condition.getServiceStatus())) {
                WHERE("s.service_status = #{serviceStatus}");
            }
        }}.toString();
    }
}
